﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MovieRecorder.CApMRCRibbonBarRecorderManager
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.Linq;


namespace DnProcessSimulateCommands.MovieRecorder;

internal class CApMRCRibbonBarRecorderManager
{
  private static string PAUSE_IMAGE_URI = "pack://application:,,,/DnProcessSimulateCommands;component/MovieRecorder/res/pause_small.png";
  private static string RESUME_IMAGE_URI = "pack://application:,,,/DnProcessSimulateCommands;component/MovieRecorder/res/resume_small.png";
  private static string STOP_IMAGE_URI = "pack://application:,,,/DnProcessSimulateCommands;component/MovieRecorder/res/stop_small.png";
  private static string RESET_IMAGE_URI = "pack://application:,,,/DnProcessSimulateCommands;component/MovieRecorder/res/recycle_small.png";
  private TxRibbonToolGroupBar m_groupbar;
  private bool m_isVisible;
  private CUiMRCRibbonBarRecorderSwitchButton buttonPauseResume;
  private CUiMRCRibbonBarRecorderButton stopButton;
  private CUiMRCRibbonBarRecorderButton buttonReset;

  public CApMRCRibbonBarRecorderManager()
  {
    this.m_groupbar = new TxRibbonToolGroupBar();
    this.m_isVisible = false;
  }

  public event EventHandler ButtonStopClick;

  public event EventHandler ButtonResetClick;

  public event EventHandler ButtonPauseResumeClick;

  public void AddToRibbonBar()
  {
    if (this.m_isVisible)
      return;
    if (!this.IsCreated)
    {
      this.CreateElements();
      TxRibbonToolGroupBarManagerEx.AddToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
    }
    else
      this.ShowToRibbonBar();
    this.m_isVisible = true;
  }

  public void RemoveFromRibbonBar()
  {
    if (!this.IsCreated)
      return;
    TxRibbonToolGroupBarManagerEx.RemoveToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
    this.UnregisterButtonEvents();
    for (int index = ((IEnumerable<ITxRibbonToolGroupElement>) this.m_groupbar.Elements).Count<ITxRibbonToolGroupElement>() - 1; index == 0; --index)
      this.m_groupbar.RemoveElement(this.m_groupbar.Elements[index]);
    this.m_isVisible = false;
  }

  public void HideFromRibbonBar()
  {
    if (!this.m_isVisible)
      return;
    TxRibbonToolGroupBarManagerEx.HideToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
    this.m_isVisible = false;
  }

  private void ShowToRibbonBar()
  {
    if (this.m_isVisible || !this.IsCreated)
      return;
    this.ResetGroupBar();
    TxRibbonToolGroupBarManagerEx.ForceUpdateToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
    TxRibbonToolGroupBarManagerEx.ShowToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
    this.m_isVisible = true;
  }

  public void UpdateDuration(string duration)
  {
    if (!this.m_isVisible || !this.IsCreated)
      return;
    (this.m_groupbar.Elements[1] as CUiMRCRibbonBarRecorderLabel).Text = duration;
    TxRibbonToolGroupBarManagerEx.ForceUpdateToolGroupBar((ITxRibbonToolGroupBar) this.m_groupbar);
  }

  private void CreateElements()
  {
    this.m_groupbar.AddElement((TxRibbonToolGroupElement) new CUiMRCRibbonBarRecorderLabel("REC"));
    this.m_groupbar.AddElement((TxRibbonToolGroupElement) new CUiMRCRibbonBarRecorderLabel("00:00:00"));
    this.buttonPauseResume = new CUiMRCRibbonBarRecorderSwitchButton(new Tuple<string, string>(MRCStringTable.MOVIE_RECORDER_PAUSE, CApMRCRibbonBarRecorderManager.PAUSE_IMAGE_URI), new Tuple<string, string>(MRCStringTable.MOVIE_RECORDER_RESUME, CApMRCRibbonBarRecorderManager.RESUME_IMAGE_URI));
    this.buttonPauseResume.Click += new EventHandler(this.buttonPauseResume_Click);
    this.m_groupbar.AddElement((TxRibbonToolGroupElement) this.buttonPauseResume);
    this.stopButton = new CUiMRCRibbonBarRecorderButton(MRCStringTable.MOVIE_RECORDER_STOP, CApMRCRibbonBarRecorderManager.STOP_IMAGE_URI);
    this.stopButton.Click += new EventHandler(this.stopButton_Click);
    this.m_groupbar.AddElement((TxRibbonToolGroupElement) this.stopButton);
    this.buttonReset = new CUiMRCRibbonBarRecorderButton(MRCStringTable.MOVIE_RECORDER_RECYCLE, CApMRCRibbonBarRecorderManager.RESET_IMAGE_URI);
    this.buttonReset.Click += new EventHandler(this.buttonReset_Click);
    this.m_groupbar.AddElement((TxRibbonToolGroupElement) this.buttonReset);
  }

  private void buttonReset_Click(object sender, EventArgs e)
  {
    if (this.ButtonResetClick == null)
      return;
    this.ButtonResetClick((object) this, new EventArgs());
  }

  private void stopButton_Click(object sender, EventArgs e)
  {
    if (this.ButtonStopClick == null)
      return;
    this.ButtonStopClick((object) this, new EventArgs());
  }

  private void buttonPauseResume_Click(object sender, EventArgs e)
  {
    if (this.ButtonPauseResumeClick == null)
      return;
    this.ButtonPauseResumeClick((object) this, new EventArgs());
  }

  private bool IsCreated
  {
    get
    {
      return this.m_groupbar != null && ((IEnumerable<ITxRibbonToolGroupElement>) this.m_groupbar.Elements).Count<ITxRibbonToolGroupElement>() > 0;
    }
  }

  private void ResetGroupBar()
  {
    foreach (IMRCRecorderRibbonToolGroupButton element in this.m_groupbar.Elements)
      element.Reset();
  }

  private void UnregisterButtonEvents()
  {
    if (this.buttonPauseResume != null)
      this.buttonPauseResume.Click -= new EventHandler(this.buttonPauseResume_Click);
    if (this.stopButton != null)
      this.stopButton.Click -= new EventHandler(this.stopButton_Click);
    if (this.buttonReset == null)
      return;
    this.buttonReset.Click -= new EventHandler(this.buttonReset_Click);
  }
}
